package com.wish.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wish.dto.PageRoomStatusDto;
import com.wish.dto.RoomInfoDto;
import com.wish.entity.RoomInfo;
import com.wish.entity.RoomVo;
import com.wish.service.IRoomInfoService;
import com.wish.vo.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 闫东浩
 * @since 2021-03-29
 */
@RestController
@RequestMapping("/room-info")
@Slf4j
public class RoomInfoController {
    @Autowired
    private IRoomInfoService roomInfoService;
    //列表
    @RequestMapping("getList")
    public Page<RoomInfo> getList( RoomVo roomVo){
        QueryWrapper<RoomInfo> wrapper = new QueryWrapper<>();
        if(roomVo.getCz()!=null && roomVo.getCz()!=""){
            wrapper.eq("r.status",roomVo.getCz());
        }
        if (roomVo.getZt()!=null && roomVo.getZt()!=""){
            wrapper.eq("h.publish_status",roomVo.getZt());
        }
        if (roomVo.getLp()!=null && roomVo.getLp()!=""){
            wrapper.like("pp.name",roomVo.getLp());
        }
        if (roomVo.getFy()!=null && roomVo.getFy()!=""){
            wrapper.like("r.room_name",roomVo.getFy());
        }
        wrapper.orderByDesc("r.recommended");
        Page<RoomInfo> page = new Page<>();
        page.setCurrent(roomVo.getPageNum());
        page.setSize(roomVo.getPageSize());
        Page<RoomInfo> pageInfo = roomInfoService.getList(wrapper,page);
        return pageInfo;
    }
    /*//是否推荐
    @RequestMapping("upd")
    public boolean upd(@RequestBody List<RoomInfo> roomInfoList){
        log.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-"+roomInfoList);
       *//* if(roomInfo.getRecommended() == 2){
            roomInfo.setRecommended(1);
            roomInfoService.updateById(roomInfo);
        }else{
            roomInfo.setRecommended(2);
            roomInfoService.updateById(roomInfo);
        }*//*
        for (RoomInfo roomInfo : roomInfoList) {
            log.info(roomInfo.getId()+"--------------------------"+roomInfo.getRecommended());
        }
        roomInfoService.updateRecommended(roomInfoList);
        return true;
    }*/
    @RequestMapping("upd")
    public boolean upd(RoomInfo roomInfo){
        if(roomInfo.getRecommended() != null &&roomInfo.getRecommended() == 2){
            roomInfo.setRecommended(1);
            roomInfoService.updateById(roomInfo);
        }else{
            roomInfo.setRecommended(2);
            roomInfoService.updateById(roomInfo);
        }
        return true;
    }

    //房源图
    @RequestMapping("/showRoom")
    public ResultEntity showRoom(PageRoomStatusDto pageRoomStatusDto) {
        System.err.println(pageRoomStatusDto);
        Map<String, Object> info = roomInfoService.roomStatusList(pageRoomStatusDto);
        return ResultEntity.ok("200", "列表查询成功", info);
    }

}
